<html>
<div id="return"></div>
<script src="/static/utils.js"></script>
<script src="/static/jquery.js"></script>
<script>
    function stringToBinary(input) {
    let binaryResult = "";
    for (let i = 0; i < input.length; i++) {
        let binaryChar = input.charCodeAt(i).toString(2);
        binaryResult += ("00000000" + binaryChar).slice(-8);
    }
        return binaryResult;
    }

    function binaryToString(input) {
        let str = '';
        for (let i = 0; i < input.length; i += 8) {
            let byte = input.slice(i, i + 8);
            str += String.fromCharCode(parseInt(byte, 2));
        }
        return str;
    }

    function simpleEncryptDecrypt(inputBinary, keyBinary) {
        let result = '';
        for (let i = 0; i < inputBinary.length; i++) {
            result += inputBinary[i] === keyBinary[i % keyBinary.length] ? '0' : '1';
        }
        return result;
    }

    function simplify_des(input, key) {
        let inputBinary = stringToBinary(input);
        let keyBinary = stringToBinary(key);
        // 加密或解密
        let encryptedBinary = simpleEncryptDecrypt(inputBinary, keyBinary);
        // 将二进制结果转换回字符串
        let result = binaryToString(encryptedBinary);
        return result;
    }
    let text = "now time: " + get_time_now();
    let key = "sec2lesson1";
    document.cookie = "token=" + btoa(simplify_des(text, key));
<!--    document.cookie = "token=123456;path=/";-->
    $.ajax({
        url: "/sec2/lesson1_1_data_api",
        success: function(data){
                $("#return").text(data.data)
            }
        })
</script>
</html>